<template>
  <div class="take-head">
    <div class="left">
      <p>
        <span>{{ takeHead.salesCount }}</span>
        <span>人购买</span>
      </p>
      <p>
        <span>{{ takeHead.praisePercent }}</span>
        <span>好评率</span>
      </p>
    </div>
    <div class="right">
      <div class="label">大家都在说：</div>
      <div class="value">
        <div :class="{active: !Object.keys(modelValue).length}"
             @click="filterClick({})">
          全部评价({{ takeHead.evaluateCount }})
        </div>
        <div :class="{active: modelValue.hasPicture}"
             @click="filterClick({hasPicture: true})">
          有图({{ takeHead.hasPictureCount }})
        </div>
        <div v-for="tag in takeHead.tags"
             :key="tag.title"
             :class="{active: modelValue.tag === tag.title}"
             @click="filterClick({tag: tag.title})">
          {{ tag.title }}({{ tag.tagCount }})
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts"
        setup>
import {getTakeHead} from '@/api/good'
import type {TakeHead} from '@/types/take'
import {ref} from 'vue'
import {useRoute} from 'vue-router'

let route = useRoute()

defineProps<{
  modelValue: any
}>()
let emits = defineEmits<{
  (e: 'update:modelValue', v: any): void
}>()

let takeHead = ref<TakeHead>({})
initTakeHead()

async function initTakeHead(): Promise<void> {
  let res = <any>await getTakeHead(<string>route.params.id)
  takeHead.value = <TakeHead>res.result
}

function filterClick(res: any) {
  emits('update:modelValue', res)
}
</script>

<style lang="less"
       scoped>
.take-head {
  display: flex;
  padding: 30px 0;
  border-bottom: 1px solid #f5f5f5;

  .left {
    width: 340px;
    height: 124px;
    padding: 20px;
    border-right: 1px solid #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;

    p {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 150px;

      span:nth-of-type(1) {
        font-size: 32px;
        color: @priceColor;
      }

      span:nth-of-type(2) {
        color: #999999;
      }
    }
  }

  .right {
    display: flex;

    .label {
      width: 100px;
      font-weight: bolder;
      text-align: right;
      line-height: 42px;
    }

    .value {
      flex: 1;
      display: flex;
      flex-wrap: wrap;

      div {
        cursor: pointer;
        width: 132px;
        height: 42px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #f5f5f5;
        border: 1px solid #e4e4e4;
        border-radius: 4px;
        margin-left: 20px;
        color: #999999;

        &.active {
          background-color: @xtxColor;
          color: white;
          border: none;
        }
      }
    }
  }
}
</style>